﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LX.Web.Excel;
using S4Store.Domain.AfterSaleKpi;

namespace S4Store.Domain.AfterSaleReport
{
    public class CarTypeReport: ExportObject
    {

        #region 数据导出
        public override bool? Discriminate(string propertyname)
        {
            if (propertyname == "BY5KSSWCJDC")
            {
                return this.BY5KSSWCJDC >= 0;
            }
            if (propertyname == "BY10KSSWCJDC")
            {
                return this.BY10KSSWCJDC >= 0;
            }
            if (propertyname == "SGCRCTCWCJDC")
            {
                return this.SGCRCTCWCJDC >= 0;
            }
            if (propertyname == "WXCRCTCWCJDC")
            {
                return this.WXCRCTCWCJDC >= 0;
            }
            if (propertyname == "ZMBRCTCWCJDC")
            {
                return this.ZMBRCTCWCJDC >= 0;
            }
            if (propertyname == "SGCCZWCJDC")
            {
                return this.SGCCZWCJDC >= 0;
            }
            if (propertyname == "WXCCZWCJDC")
            {
                return this.WXCCZWCJDC >= 0;
            }
            if (propertyname == "MBCZWCJDC")
            {
                return this.MBCZWCJDC >= 0;
            }
            if (propertyname == "DCCZWCD")
            {
                return this.DCCZWCD >= 100;
            }
            if (propertyname == "SCXBWCJDC")
            {
                return this.SCXBWCJDC >= 0;
            }
            if (propertyname == "ECXBWCJDC")
            {
                return this.ECXBWCJDC >= 0;
            }
            if (propertyname == "XBMBWCJDC")
            {
                return this.XBMBWCJDC >= 0;
            }
            return null;
        }
        #endregion


        public int Year { get; set; }
        public int Month { get; set; }
        public int Day { get; set; }
        public List<AfterSaleCarTypeMonthConfig> M { get; set; }
        public List<AfterSaleCarTypeDayInput> D { get; set; }
        public Store Store { get; set; }

        public CarTypeReport()
        {
            M = new List<AfterSaleCarTypeMonthConfig>();
            D = new List<AfterSaleCarTypeDayInput>();
        }

        protected bool showlastday = false;
        public virtual void ShowLastDay(bool value)
        {
            showlastday = value;
        }

        [Export("车型")]
        public string CarBrand
        {
            get;
            set;
        }

        [Export("本月应实施5K保养数")]
        public int BYYSS5KBYS
        {
            get
            {
                return M.Sum(O => O.BYYSS5KBYS_MonthTarget5K);
            }
        }

        [Export("本月应实施10K保养数")]
        public int BYYSS10KBYS
        {
            get
            {
                return M.Sum(O => O.BYYSS10KBYS_MonthTarget10k);
            }
        }

        [Export("本月事故车入厂台次目标")]
        public int BYSGCRCTCMB
        {
            get
            {
                return M.Sum(O => O.BYSGCRCTCMB_MonthAacidentCarToFactoryTarget);
            }
        }

        [Export("本月维修车入厂台次目标")]
        public int BYWXCRCTCMB
        {
            get
            {
                return M.Sum(O => O.BYWXRCTCMB_MonthMaintainCarToFactoryTarget);
            }
        }

        [Export("目标入厂台次")]
        public int MBRCTC
        {
            get {
                return M.Sum(O => O.BYWXRCTCMB_MonthMaintainCarToFactoryTarget + O.BYYSS5KBYS_MonthTarget5K + O.BYYSS10KBYS_MonthTarget10k + O.BYSGCRCTCMB_MonthAacidentCarToFactoryTarget);
            }
        }

        [Export("5k保养目标产值")]
        public decimal _5KBYMBCZ
        {
            get {
                return M.Sum(o => o.WQBYMBCZ_5KMaintenanceTargetValue);
            }
        }

        [Export("10k保养目标产值")]
        public decimal _10KBYMBCZ
        {
            get
            {
                return M.Sum(o => o.SQBYMBCZ_TenKMaintenanceTargetValue);
            }
        }

        [Export("本月事故车维修产值目标")]
        public decimal BYSGCCZMB
        {
            get
            {
                return M.Sum(o => o.BYSGCCZBM_MonthAacidentCarTargetValue);
            }
        }

        [Export("本月维修车产值目标")]
        public decimal BYWXCCZMB
        {
            get {
                return M.Sum(O => O.BYWXCZMB_MonthMaintenanceTargetValue);
            }
        }

        [Export("目标售后产值")]
        public decimal MBSHCZ
        {
            get {
                return M.Sum(o => o.WQBYMBCZ_5KMaintenanceTargetValue + o.SQBYMBCZ_TenKMaintenanceTargetValue + o.BYSGCCZBM_MonthAacidentCarTargetValue + o.BYWXCZMB_MonthMaintenanceTargetValue);
            }
        }

        [Export("首次续保台次目标")]
        public int SCXBTCMB
        {
            get {
                return M.Sum(o=>o.SCXBTCMB_FirstRenewTarget);
            }
        }

        [Export("二次续保台次目标")]
        public int ECXBTCMB
        {
            get
            {
                return M.Sum(o => o.ECXBTCMB_SecondRenewTarget);
            }
        }

        [Export("目标续保台次总数")]
        public int MBXBTCZS
        {
            get {
                return M.Sum(o => o.SCXBTCMB_FirstRenewTarget + o.ECXBTCMB_SecondRenewTarget);
            }
        }

        [Export("目标单车产值")]
        public decimal MBDCCZ
        {
            get
            { 
                if(MBRCTC==0) return 0;
                return MBSHCZ / MBRCTC;
            }
        }

        [Export("累计完成事故入厂台次")]
        public int LJWCSGCRCTC
        {
            get
            {
                return D.Sum(o => o.SGRCTC_AccidentCarToFactory);
            }
        }

        [Export("累计完成维修入厂台次")]
        public int LJWCWXRCTC
        {
            get
            {
                return D.Sum(o => o.WXRCTC_MaintainCarToFactory);
            }
        }

        [Export("本月实际实施5K保养数")]
        public int BYSJSS5KBYS
        {
            get
            {
                return D.Sum(o => o.WKBYS_Maintain5KNum);
            }
        }

        [Export("本月实际实施10K保养数")]
        public int BYSJSS10KBYS
        {
            get
            {
                return D.Sum(o => o.SQBYS_Maintain10KNum);
            }
        }

        [Export("累计完成入厂台次")]
        public int LJWCRCTC
        {
            get
            {
                return D.Sum(o => o.SGRCTC_AccidentCarToFactory + o.WXRCTC_MaintainCarToFactory + o.WKBYS_Maintain5KNum + o.SQBYS_Maintain10KNum);
            }
        }

        [Export("5K保养实际产值")]
        public decimal _5KBYSJCZ
        {
            get
            {
                return D.Sum(o => o.WQBYCZ_Maintain5KValue);
            }
        }

        [Export("10K保养实际产值")]
        public decimal _10KBYSJCZ
        {
            get
            {
                return D.Sum(o => o.SQBYCZ_Maintain10KValue);
            }
        }

        [Export("其他维修产值")]
        public decimal QTWXCZ
        {
            get
            {
                return D.Sum(o => o.QTWXCZ_MaintainOtherValue);
            }
        }

        [Export("累计完成事故车产值")]
        public decimal LJWCSGCCZ
        {
            get
            {
                return D.Sum(o => o.SGCCZ_AccidentCarValue);
            }
        }

        [Export("累计常规维修产值")]
        public decimal LJCGWXCZ
        {
            get
            {
                return _5KBYSJCZ + _10KBYSJCZ + QTWXCZ;
            }
        }

        [Export("累计完成售后总产值")]
        public decimal LJWCSHZCZ
        {
            get {
                return LJCGWXCZ + LJWCSGCCZ;
            }
        }

        [Export("累计精品销售额")]
        public decimal LJJPXSE
        {
            get
            {
                return D.Sum(o => o.JPXSE_BestSaleValue);
            }
        }

        [Export("累计养护产品销售额")]
        public decimal LJYHCPXSE
        {
            get
            {
                return D.Sum(o => o.YHCPXSE_MaintenanceSaleValue);
            }
        }

        [Export("首次续保实际完成台次")]
        public decimal SCXBSJWCTC
        {
            get
            {
                return D.Sum(o => o.SCXB_FirstRenewNum);
            }
        }

        [Export("二次续保实际完成台次")]
        public decimal ECXBSJWCTC
        {
            get
            {
                return D.Sum(o => o.ECXB_SecondRenewNum);
            }
        }

        [Export("续保台次完成总数")]
        public decimal XBTCZS
        {
            get
            {
                return D.Sum(o => o.SCXB_FirstRenewNum + o.ECXB_SecondRenewNum);
            }
        }

        [Export("本月5K实施完成率",Format="{0}%")]
        public decimal BY5KSSWCL
        {
            get
            {
                if (BYYSS5KBYS == 0) return 0;
                return (decimal)BYSJSS5KBYS / (decimal)BYYSS5KBYS * 100;
            }
        }

        [Export("本月5K实施完成进度差", Format = "{0}%", BackBround= ExcelCellBg.Warning)]
        public decimal BY5KSSWCJDC
        {
            get
            {
                if (BY5KSSWCL == 0) return 0;
                return BY5KSSWCL-100;
            }
        }

        [Export("本月10K实施完成率", Format = "{0}%")]
        public decimal BY10KSSWCL
        {
            get
            {
                if (BYSJSS10KBYS == 0) return 0;
                return (decimal)BYSJSS10KBYS / (decimal)BYYSS10KBYS * 100;
            }
        }

        [Export("本月10K实施完成进度差", Format = "{0}%", BackBround = ExcelCellBg.Warning)]
        public decimal BY10KSSWCJDC
        {
            get
            {
                if (BY10KSSWCL == 0) return 0;
                return BY10KSSWCL - 100;
            }
        }

        [Export("事故车入厂台次完成率", Format = "{0}%")]
        public decimal SGCRCTCWCL
        {
            get
            {
                if (BYSGCRCTCMB == 0) return 0;
                return (decimal)LJWCSGCRCTC / (decimal)BYSGCRCTCMB*100;
            }
        }

        [Export("事故车入厂台次完成进度差", Format = "{0}%", BackBround = ExcelCellBg.Warning)]
        public decimal SGCRCTCWCJDC
        {
            get
            { 
                if(SGCRCTCWCL==0) return 0;
                return SGCRCTCWCL - 100;
            }
        }

        [Export("维修车入厂台次完成率", Format = "{0}%")]
        public decimal WXCRCTCWCL
        {
            get
            {
                if (BYWXCRCTCMB == 0) return 0;
                return (decimal)LJWCWXRCTC / (decimal)BYWXCRCTCMB*100;
            }
        }

        [Export("维修车入厂台次完成进度差", Format = "{0}%", BackBround = ExcelCellBg.Warning)]
        public decimal WXCRCTCWCJDC
        {
            get
            {
                if (WXCRCTCWCL == 0) return 0;
                return WXCRCTCWCL - 100;
            }
        }

        [Export("总目标入厂台次完成率", Format = "{0}%")]
        public decimal ZMBRCTCWCL
        {
            get
            {
                if (MBRCTC == 0) return 0;
                return (decimal)LJWCRCTC / (decimal)MBRCTC * 100;
            }
        }

        [Export("总目标入厂台次完成进度差", Format = "{0}%", BackBround = ExcelCellBg.Warning)]
        public decimal ZMBRCTCWCJDC
        {
            get
            {
                if (ZMBRCTCWCL == 0) return 0;
                return ZMBRCTCWCL - 100;
            }
        }

        [Export("事故车产值完成率", Format = "{0}%")]
        public decimal SGCCZWCL
        {
            get
            {
                if (BYSGCCZMB == 0) return 0;
                return (decimal)LJWCSGCCZ / (decimal)BYSGCCZMB * 100;
            }
        }

        [Export("事故车产值完成进度差", Format = "{0}%", BackBround = ExcelCellBg.Warning)]
        public decimal SGCCZWCJDC
        {
            get
            {
                if (SGCCZWCL == 0) return 0;
                return SGCCZWCL - 100;
            }
        }

        [Export("维修车产值完成率", Format = "{0}%")]
        public decimal WXCCZWCL
        {
            get
            {
                if (BYWXCCZMB == 0) return 0;
                return (decimal)LJCGWXCZ / (decimal)BYWXCCZMB * 100;
            }
        }

        [Export("维修车产值完成进度差", Format = "{0}%", BackBround = ExcelCellBg.Warning)]
        public decimal WXCCZWCJDC
        {
            get
            {
                if (WXCCZWCL == 0) return 0;
                return WXCCZWCL - 100;
            }
        }

        [Export("目标产值完成率", Format = "{0}%")]
        public decimal MBCZWCL
        {
            get
            {
                if (MBSHCZ == 0) return 0;
                return (decimal)LJWCSHZCZ / (decimal)MBSHCZ * 100;
            }
        }

        [Export("目标产值完成进度差", Format = "{0}%", BackBround = ExcelCellBg.Warning)]
        public decimal MBCZWCJDC
        {
            get
            {
                if (MBCZWCL == 0) return 0;
                return MBCZWCL - 100;
            }
        }

        [Export("实际平均单车产值")]
        public decimal SJPJDCCZ
        {
            get
            {
                if (LJWCRCTC == 0) return 0;
                return LJWCSHZCZ / (decimal)LJWCRCTC;
            }
        }

        [Export("单车产值完成度", Format = "{0}%", BackBround = ExcelCellBg.Warning)]
        public decimal DCCZWCD
        {
            get
            {
                if (MBDCCZ == 0) return 0;
                return SJPJDCCZ / MBDCCZ*100;
            }
        }

        [Export("首次续保完成率", Format = "{0}%")]
        public decimal SCXBWCL
        {
            get {
                if (SCXBTCMB == 0) return 0;
                return (decimal)SCXBSJWCTC / (decimal)SCXBTCMB*100;
            }
        }

        [Export("首次续保完成进度差", Format = "{0}%", BackBround = ExcelCellBg.Warning)]
        public decimal SCXBWCJDC
        {
            get
            {
                if (SCXBWCL == 0) return 0;
                return SCXBWCL - 100;
            }
        }

        [Export("二次续保完成率", Format = "{0}%")]
        public decimal ECXBWCL
        {
            get
            {
                if (ECXBTCMB == 0) return 0;
                return (decimal)ECXBSJWCTC / (decimal)ECXBTCMB * 100;
            }
        }

        [Export("二次续保完成进度差", Format = "{0}%", BackBround = ExcelCellBg.Warning)]
        public decimal ECXBWCJDC
        {
            get
            {
                if (ECXBWCL == 0) return 0;
                return ECXBWCL - 100;
            }
        }

        [Export("续保目标完成率", Format = "{0}%")]
        public decimal XBMBWCL
        {
            get
            {
                if (MBXBTCZS == 0) return 0;
                return (decimal)XBTCZS / (decimal)MBXBTCZS * 100;
            }
        }

        [Export("续保目标完成进度差", Format = "{0}%", BackBround = ExcelCellBg.Warning)]
        public decimal XBMBWCJDC
        {
            get
            {
                if (XBMBWCL == 0) return 0;
                return XBMBWCL - 100;
            }
        }



    }
}
